list=[3,0,2,3,1,5,7,4,6,8]

class ListBean:
    def __init__(self,data,next):
        super().__init__()
        self.data=data
        self.next=next

def method1(list):
    head=ListBean(None,None)
    lastData=None
    for i in list:
        lastData=ListBean(i,lastData)
    head.next=lastData
    printLinkList(head)
    
def method2(list):
    head=ListBean(None,None)
    lastData=head
    for i in list:
        lastData.next=ListBean(i,None)
        lastData=lastData.next
    printLinkList(head)
    sortLinkList(head)

def sortLinkList(list):
    newLinkList=ListBean(None,None)
    op=list.next
    oprep=list
    while op!=None:
        oprep=op
        op=op.next
        p=newLinkList.next
        prep=newLinkList
        while True:
            if p==None or p.data>oprep.data:
                prep.next=oprep
                if p==None:
                    oprep.next=None
                else:
                    oprep.next=p
                break
            prep=p
            p=p.next
    print("排序后")
    printLinkList(newLinkList)


def printLinkList(head):
    print("*****************************")
    current=head
    while True:
        current=current.next
        if current!=None:
            print(current.data)
        else:
            break
# method1(list.copy())
method2(list.copy())
